//
// isr.c -- High level interrupt service routines and interrupt request handlers.
//          Part of this code is modified from Bran's kernel development tutorials.
//          Rewritten for JamesM's kernel development tutorials.
//

#include "common.h"
#include "isr.h"
#include "monitor.h"

isr_t interrupt_handlers[256];

// This gets called from our ASM interrupt handler stub.
void isr_handler(registers_t regs)
{
	printk("Recieved Interrupt. %d Error Code : %d\n", regs.int_no, regs.err_code);

}

// This gets called from the irq_common_stub
void irq_handler(registers_t regs){

	
	if (regs.int_no >=40){
		outb(0xA0, 0x20);
		// This was the signal to slave.
	}	
	// Send the signal to master.
	outb(0x20, 0x20);

	if (interrupt_handlers[regs.int_no] != 0){
		isr_t handler = interrupt_handlers[regs.int_no];
		handler(regs);
	}
}

void register_interrupt_handler(uint8 n, isr_t handler){
	interrupt_handlers[n] = handler;
}
